import java.util.Scanner;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2022/12/9 16:28
 * @copyright: 博为峰
 */
public class Stu04 {
    public static void login(Scanner scanner) {
        do {
            System.out.println("请输入用户名");
            String name = scanner.nextLine();
            System.out.println("请输入密码");
            String password = scanner.nextLine();
            if (name.equals("zhangsan") && password.equals("123")) {
                break;
            }
        } while (true);
    }

    public static void addStu(Student[] stus, int index) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入ID");
        String id = scanner.nextLine();
        System.out.println("请输入姓名");
        String name = scanner.nextLine();
        Student stu = new Student();
        stu.id = id;
        stu.name = name;
        stus[index] = stu;
    }

    public static void setStu(Scanner scanner, Student[] stus) {
        //1.提示用户输入要修改的学生ID和name
        System.out.println("请输入要修改的学生ID");
        //2.接收用户输入的学生ID
        String uid = scanner.nextLine();
        //3.接收用户输入的学生name
        String uname = scanner.nextLine();
        for (int i = 0; i < stus.length; i++) {
            Student stu = stus[i];
            if (stu != null && stu.id.equals(uid)) {
                stu.name = uname;
            }
        }
    }

    public static void main(String[] args) {
        System.out.println("1.登录2.t退出");
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        //登录，如果输入错误，可以再次登录，添加一个学生，遍历
        switch (s) {
            case "1":
                login(scanner);
                Student[] stus = new Student[100];
                int index = -1;
                do {
                    System.out.println("1.新增2.删除3.修改4.遍历5.退出");
                    String choice = scanner.nextLine();
                    switch (choice) {
                        case "1":
                            index++;
                            addStu(stus, index);
                            break;
                        case "2":
                            //删除
                            break;
                        case "3":
                            setStu(scanner, stus);
                            break;
                        case "4":
                            //遍历
                            for (int i = 0; i < stus.length; i++) {
                                if (stus[i] != null) {
                                    Student stu = stus[i];
                                    System.out.println(stu.id + "," + stu.name);
                                }
                            }
                            break;
                        case "5":
                            //退出
                            break;
                        default:
                            System.out.println("请输入正确的操作");
                    }
                } while (true);

//                break;
            case "2":
                //退出
                break;
            default:
                System.out.println("请输入正确的操作");
        }
    }
}
